/*
 * This class is for maintaining the statistics of the database,
 * with a statistic pool and functions to add, update and retrieve statistics from it.
 * 
 * (c) Hongbin Kuang
 * 04/23/2009
 * V1.0
 */

package costEstimation;

import java.util.*;

public class StatList {
	private ArrayList<Stat> pool = new ArrayList<Stat>(); // The list of all statistics
	
	// Functions for adding, updating and retrieving statistics
	public boolean addStat(String name, double value)
	{
		Stat tmpStat = new Stat(name);
		tmpStat.updateValue(value);
		return pool.add(tmpStat);
	}
	
	public boolean updateStat(String name, double value)
	{
		Stat tmpStat = new Stat(name);
		int index = pool.indexOf(tmpStat);
		if (index == -1)
			return false;
		
		Stat targetStat = pool.get(index);
		targetStat.updateValue(value);
		
		return true;
	}
	
	public double getStat(String name)
	{
		Stat tmpStat = new Stat(name);
		int index = pool.indexOf(tmpStat);
		if (index == -1)
			return -1;
		
		Stat targetStat = pool.get(index);
		return targetStat.getValue();
	}
}
